home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / tlx_sq21.zip / MEGAMAIL.SLT < prev    next >
Text File  |  1992-03-20  |  11KB  |  343 lines

  1. //-----------------------------------------------------------
  2. // MEGAMAIL.SL?   Telix script to fetch mail from a PCBoard BBS.
  3. //
  4. // This script is normally called from the script PCB.SLC.
  5. //
  6. // Please look at the comments through the whole file, and modify to
  7. // suit your needs, BEFORE you use it. Then recompile with CS MEGAMAIL.
  8. //-----------------------------------------------------------
  9.  
  10. // If you have suggestions for improving this script, please suggest
  11. // improvements to me via old-fashioned snail-mail to:
  12.  
  13. // Author:  Inge Vabekk
  14. //          Hamangskogen 108
  15. //          N-1300 SANDVIKA
  16. //          NORWAY
  17. //          tel. (472) 546 396
  18.  
  19. str myprot    [2]             // My protocol
  20.    ,codename [10]             // BBS codename.
  21.    ,help     [80]             // Help line.
  22.    ,runstr   [80]             // DSZ runstring (if used).
  23.                               // Script and global names:
  24.    ,global     []="GLOBAL"    // Global script.
  25.    ,Cprot      []="CPROT"     // Current protocol.
  26.    ,prompt     []="PROMPT"    // Current command prompt.
  27.    ,Cname      []="CNAME"     // Codename of current BBS.
  28.    ,mdir       []="MDIR"      // Mail directory.
  29.    ,dsz        []="DSZ"       // Code for DSZ (if in use).
  30.    ;     
  31.  
  32. int tol = 300                 // No activity for 30 sec.
  33.    ,tmark                     // makes script time out.
  34.    ,stat
  35.    ,BBSver                    // PCB version
  36.    ;
  37.  
  38. //-----------------------------------------------------------
  39. // MEGAmail script is entered here.                                   
  40. //-----------------------------------------------------------
  41.  
  42. main()
  43. {
  44. int c, i, j                            // For tracking:
  45.    ,un                                 // Upload Now
  46.    ,dn                                 // Download Now
  47.    ,rt                                 // Return.
  48.    ,pd                                 // Back to ProDoor.
  49.    ,W;                                 // Still working...
  50.  
  51.   entry();                             // Updates status bar.
  52.   read (cprot,myprot) ;                // Get current BBS protocol.
  53.  
  54.   un = track ("Upload Your",0);        // Wait for message.
  55.   pd = track ("Prodoor",1);            // Prodoor again.
  56.   W  = track ("se wait ...",0);        // Returning.
  57.   tmark = timer_start (tol);           // Give me a minute.
  58.  
  59.   while ((stat=trig()) > 0)            // answer any questions.
  60.   { if (stat == un)
  61.       break;                           // Upload Now?
  62.       goto done;                       // Door aborted.
  63.   }
  64.   release();
  65.   if (!carrier()) goto done;           // Fail?     
  66.  
  67.   waitfor ("^J",1);                    // Wait for linefeed.
  68.   terminal();
  69.   for (w=gety(); w>=0; --w)            // Get the "Upload your" line.
  70.   { vgetchrs(0,w,help,0,80);
  71.     if ((j=strposi (help,".UL",0)) > 0)// Packet name in this line?
  72.       break;
  73.   }
  74.   if (w <= 0)
  75.   { megabort();
  76.     goto done;
  77.   }
  78.  
  79.   for (i=--j; i > 0; --i)              // Find first character.
  80.   { if (subchr(help,i) == ' ') break;
  81.   }
  82.   substr (help,++i,j-i,codename);      // Move it down.
  83.   write (cname,codename);              // Save BBS ID-code.
  84.  
  85. // Start sending the mail packet.
  86. // See if we can find the upload file.
  87. // ----------------------------------------------------------
  88.  
  89.   help = _up_dir;                      // Get upload directory.
  90.   i = strlen(help)-1;
  91.   if (subchr(help,i)!='\')             // Append "\" if  
  92.     strcat (help,"\");                 // necessary.
  93.   strcat (help,codename);              // Copy codename to filename.
  94.   strcat (help,".UL");                 // Add extension.
  95.   prints ("");
  96.   printsc ("T²: Filename: ");
  97.   prints (help);
  98.  
  99.   if (filesize(help) <= 0)             // No file to send?
  100.   { megabort(help);
  101.     goto done;
  102.   }
  103.   send_file();                         // Send the mail file.
  104.  
  105. // Define new strings for tracking.
  106. //-----------------------------------------------------------
  107.  
  108.   dn = track ("gin Your",0);           // Download now.
  109.   rt = track ("system..",0);           // Return to system.
  110.   W  = track ("rking On",0);           // Still working....
  111.  
  112.   tmark = timer_start (tol);           // Give me a minute.
  113.  
  114.   while ((stat=trig()) > 0)            // answer any questions.
  115.   { if (stat == rt)                    // Return to system?
  116.       goto abort;
  117.  
  118.     else if (stat == dn)               // Download now?
  119.       break;
  120.  
  121.     else if (stat == W)                // Still working?
  122.       ;                                // Just wait....
  123.   }
  124.   release();                           // Free all tracks and timer.
  125.   get_file();
  126.   if (carrier()) goto done;
  127.  
  128. abort:
  129.   release();
  130.   failtone();
  131.   return (-1);
  132.  
  133. done:
  134.   release();
  135.   goodtone();
  136.   return (0);
  137. }
  138.  
  139. //-----------------------------------------------------------
  140. // Send upload mail file.
  141. //-----------------------------------------------------------
  142.  
  143. send_file()
  144. {
  145. int c;
  146.  
  147.   if (read (dsz,runstr) > 0)           // DSZ?
  148.   { strcat (runstr,help);              // Add filename to runstring.
  149.     while ((c=strchr(runstr,0,'\')) > 0)
  150.       setchr (runstr,c,'/');           // Replace '\' by '/'.
  151.     exec (dsz,runstr);                 // Use DSZ.
  152.     flushbuf();                        // Flush input buffer.
  153.   }
  154.   else
  155.     send (subchr(myprot,0),help);      // Send file.
  156. }
  157.  
  158. //-----------------------------------------------------------
  159. // Get download mail file.
  160. //-----------------------------------------------------------
  161.  
  162. get_file()
  163. {
  164. int save;
  165.   save = _zmod_auto;                   // Save auto zmodem indicator.
  166.   _zmod_auto = 0;
  167.  
  168.   if (read (dsz,runstr) < 0)           // DSZ not defined:
  169.   { help = _down_dir;                  // Save download dir.
  170.     read (mdir,_down_dir);             // and change it.
  171.     receive (subchr(myprot,0),"");
  172.     _down_dir = help;                  // Restore download dir.
  173.   }
  174.   else
  175.   { newdir (_down_dir);                // DSZ: Change directory.
  176.     strcat (runstr," r");              // Add parameters: Receive.
  177.     strlower (myprot);                 // Protocol.
  178.     strcat (runstr,myprot);
  179.     strcat (runstr," -y");             // OK to overwrite.
  180.     exec (dsz,runstr);                 // Use DSZ.
  181.     flushbuf();                        // Flush input buffer.
  182.     newdir (_telix_dir);               // Go back to TELIX directory!
  183.   }
  184.  
  185.   _zmod_auto = save;                   // restore auto zmodem indicator.
  186.   _down_dir = help;                    // Restore download dir.
  187. //read (prompt,help);                  // Get command prompt.
  188. //waitfor (help,20);                   // Wait for next command.
  189. }
  190.  
  191. //----------------------------------------------------------
  192. // Abort Megamail door.
  193. //-----------------------------------------------------------
  194.  
  195. megabort(str help)
  196. {
  197. int i, t1;
  198.  
  199.   for (i=0; i<3; ++i)                  // Three short beeps.
  200.   { tone (2400,6);
  201.     delay(1);
  202.   }
  203.  
  204.   mess ("T²: File missing:");
  205.   mess (help);
  206.   mess ("No upload mail - Attempting to abort MegaMail door");
  207.  
  208.   t1 = track (" Command",0);           // Command
  209.   track (" wait ..",0);                // Please wait...
  210.   track ("Prodoor",1);                 // Prodoor again.
  211.  
  212.   i=0;
  213.   tmark = timer_start (tol);           // Give me thirty seconds.
  214.   do  
  215.   { cputs ("^X");                      // Send Control-X.
  216.     delay (2);                         // as long as we're online.
  217.     if ((stat=track_hit(0)))           // If trigger,
  218.       timer_restart (tmark,tol);       // reset timer.
  219.     if (stat==t1)                      // If command, count to
  220.     { if (++i > 2) break;              // three to remove CNTL-X-es
  221.       cputs ("^M");                    // from his input buffer.
  222.     }
  223.   } while (!time_up(tmark) && carrier());
  224.  
  225.   return;                              // Return.
  226. }
  227.  
  228. //-----------------------------------------------------------
  229. // Routine to update colors and status bar.
  230. //-----------------------------------------------------------
  231.  
  232. entry ()
  233. {
  234.   _back_color = 1;
  235.   _fore_color = 14;
  236.   update_term();
  237. }
  238.  
  239. //---------------------------